<extend name="Base:base" />
<block name="head">
    <script type="text/javascript" charset="utf-8">
        window.UEDITOR_HOME_URL = "__ROOT__/Public/ueditor/";  //UEDITOR_HOME_URL、config、all这三个顺序不能改变
    </script>
    <script type="text/javascript" charset="utf-8" src="__ROOT__/Public/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__ROOT__/Public/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/js/jquery-ui-1.10.4.custom.js"></script>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/jquery-ui-1.10.4.custom.css" />
</block>
<block name="title">{$title}</block>
<block name="content">
    <form action="{:U('Admin/Product/addDo')}" enctype="multipart/form-data" method="post">
        <table class="table">
            <tr>
                <th>产品名称</th>
                <td><input type="text" name="name" value="" /></td>
                <th>所属类别</th>
                <td colspan="2">
                    <select name="type_id" class="brand">
                        <option value=""></option>
                        <foreach name="categories" item="category">
                            <option value="{$category.id}">{$category.name}</option>
                        </foreach>
                    </select>
                </td>
                <th>是否显示</th>
                <td colspan="2">
                    <input type="radio" name="is_active" value="1" />显示
                    <input type="radio" name="is_active" value="0" />不显示
                </td>  
            </tr>
            <tr>
                <th>原厂编号</th>
                <td><input type="text" name="factory_num" /></td>
                <th>产品编号</th>
                <td><input type="text" name="product_num" /></td>
                <th>CAS编号</th>
                <td><input type="text" name="cas_num" /></td>
                <th>货号</th>
                <td><input type="text" name="cargo_num" /></td>
            </tr>
            <tr>
                <th>规格</th>
                <td colspan="5"><input type="text" style="width: 500px;"name="standard"></td>
                <th>是否推荐</th>
                <td colspan="2">
                    <input type="radio" name="is_introduce" value="1" />推荐
                    <input type="radio" name="is_introduce" value="0" />不推荐
                </td>  
            </tr>
            <tr>
                <th>包装</th>
                <td><input type="text" name="pack"/></td>
                <th>单位</th>
                <td><input type="text" name="unit" /></td>
                <th>目录价格</th>
                <td><input type="text" name="list_price" /></td>
                <th>产品图片</th>
                <td><input type="file" name="imageurl" /></td>
            </tr>
            <tr>
                <th colspan="8">产品内容</th>
            </tr>
            <tr>
                <td colspan="8"><textarea name="content" id="content"></textarea></td>
            </tr>
        </table>
        <input type="submit" value="保存修改"/>
    </form>
    <script>
        UE.getEditor('content', {
            "initialFrameWidth": "100%",
            "initialFrameHeight": 250,
        });
        $(function() {
            $(".category").change(function() {
                var category_id = $(this).val();
                var brand_select = $('select[name="brand_id"]');
                $.ajax({
                    type: "get",
                    url: "{:U('Admin/HelpMisc/getBrand')}",
                    data: {category_id: category_id},
                    dataType: "json",
                    success: function(data) {
                        $(brand_select).find("option").remove();
                        for (var i in data) {
                            var id = data[i].id;
                            var text = data[i].name;
                            var option = $('<option>').val(id).text(text);
                            $(brand_select).append(option);
                            
                        }
                        if(category_id == 1){
                            $('input[name="product_num"]').attr("disabled", "disabled");
                            $('input[name="cas_num"]').removeAttr("disabled");
                        }else{
                            $('input[name="product_num"]').removeAttr("disabled")
                            $('input[name="cas_num"]').attr("disabled", "disabled");
                        }
                    }
                });
            });
        });
    </script>
</block>